import myutil.MyInput;
public class MooresVotingAlgorithm {

	public static int arr[] = {1,2,3,4,1,1};
	
	public static int findCandidate (){
		int i=1;
		int count = 1;
		int candid= arr[0];
		while(i < arr.length){
			if(arr[i]==candid){
				count++;
			} else if (count ==0 ){
				candid = arr[i];
				count = 1;
			} else {
				count--;
			}
			i++;
		}
		return candid;
	}
	
	public static int checkCandidate(int candid){
		int i=0;
		int count =0;
		while(i <arr.length){
			if(arr[i++]==candid) count++;
		} 
		
		if(count > arr.length/2) return candid;
		else return -1;
		
	}
	public static void main(String[] args) {

		int c= findCandidate();
		System.out.println(checkCandidate(c));
		
	}

}
